package reign.engine.structures;

import java.util.HashMap;
import java.util.Iterator;

import reign.engine.Constants;
import reign.engine.structures.decks.SupplyDeck;

public class Supply {
	private HashMap<String,SupplyDeck> decks;
	public Supply()
	{
		decks = new HashMap<String,SupplyDeck>();
	}
	
	public void initSupply()
	{
		Iterator<SupplyDeck> decksAdded = decks.values().iterator();
		while(decksAdded.hasNext())
		{
			decksAdded.next().reset();
		}
	}
	
	public boolean addDeck(String name,SupplyDeck addMe)
	{
		if(decks.size() < Constants.SUPPLY_DECK_LIMIT)
		{
			decks.put(name, addMe);
		}
		return false;
	}
	
	public SupplyDeck[] addDecks(SupplyDeck [] addme)
	{
		int i = 0;
		for(; i < addme.length;i++)
		{
			if(addDeck(addme[i].getName(),addme[i]) == false)
			{
				break;
			}
		}
		SupplyDeck [] leftOvers = new SupplyDeck[addme.length-i];
		int offset = i;
		for(; i < addme.length;i++)
		{
			leftOvers[i-offset] = addme[i];
		}
		return leftOvers;
	}
	
	public boolean isAdded(String name)
	{
		return (decks.get(name) != null);
	}
	
	public boolean exists(String name, SupplyDeck exists)
	{
		SupplyDeck getIt = decks.get(name);
		return (getIt.equals(exists));
	}
	
	public void remove(String name)
	{
		decks.remove(name);
	}
}
